import AbstractCamera from './AbstractCamera';
import { CameraOptions } from '../typings/PanoramaType';

class Camera extends AbstractCamera {
    constructor(width: number, height: number, options: CameraOptions = {}) {
        super(width, height);

        if (typeof options.bearing === 'number') {
            this._bearing = options.bearing;
        }

        if (typeof options.pitch === 'number') {
            this._pitch = Camera.processPitch(options.pitch);
        }

        if (options.center) {
            this._center.set(options.center.x, options.center.y);
        }

        this._calcProjectionMatrix();
        this._calcViewMatrix();
    }

    set(params: CameraOptions) {
        const { bearing, pitch, center } = params;

        if (typeof bearing === 'number') {
            this._bearing = Camera.processBearing(bearing);
        }

        if (typeof pitch === 'number') {
            this._pitch = Camera.processPitch(pitch);
        }

        if (center) {
            this._center.set(center.x, center.y);
        }
        this._calcViewMatrix();
    }

    resize(width: number, height: number) {
        this._width = width;
        this._height = height;

        this._calcProjectionMatrix();
        this._calcViewMatrix();
    }
}

export default Camera;
